<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        label{
            width: 90px;

            display: inline-block;

            text-align: right;
        }
        img{
            margin-left: 80px;
            margin-top: 20px;
        }
        input[type='submit']{
            margin-left: 110px;
            margin-top: 10px;
        }
</style>
</head>
<body>
    <form action="">
        <label>用户名</label>
        <input type="text" id="uname"><br>
        <label >密码</label>
        <input type="password" id="pwd"><br>
        <label >验证码</label>
        <input type="text" id="captcha"><br>
        <img src="http://kg.zhaodashen.cn/v1/public/captcha.jsp" alt=""><br>
        <input type="submit" value="登录">

        <label style="margin-left: 40px;  color: rgb(188, 179, 179);">七天免登陆:</label>

        <input type="checkbox"><br>

    </form>
    <script src="./axios.js"></script>

    <script>
        document.querySelector('input[type=submit]').onclick=async function(ev){
            let e=ev||window.event;
            e.preventDefault();
            let uname=document.querySelector('#uname').value;
            let pwd=document.querySelector('#pwd').value;
            let captcha=document.querySelector('#captcha').value;
            let res=await post('http://kg.zhaodashen.cn/v1/public/login.jsp',{uname,pwd,captcha})
            if(res.meta.state===200){
                if(document.querySelector('input[type=checkbox]').checked){
                    localStorage.setItem('uname',res.data.uname)
                    localStorage.setItem('expires',(new Date).getTime()+1000*10)
                }else{
                    sessionStorage.setItem('uname',res.data.uname)
                }
                location.href='./member.html'
            }else{
                alert(res.meta.msg)
            }
        }
        document.querySelector('img').onclick=function(){
            document.querySelector('img').src='http://kg.zhaodashen.cn/v1/public/captcha.jsp?'+(new Date).getTime();
        }
    </script>
</body>
</html>